home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / commando.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  8KB  |  290 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *commando_bgvideoram,*commando_bgcolorram;
  15. size_t commando_bgvideoram_size;
  16. unsigned char *commando_scrollx,*commando_scrolly;
  17. static unsigned char *dirtybuffer2;
  18. static struct osd_bitmap *tmpbitmap2;
  19. static int flipscreen;
  20.  
  21.  
  22.  
  23. /***************************************************************************
  24.  
  25.   Convert the color PROMs into a more useable format.
  26.  
  27.   Commando has three 256x4 palette PROMs (one per gun), connected to the
  28.   RGB output this way:
  29.  
  30.   bit 3 -- 220 ohm resistor  -- RED/GREEN/BLUE
  31.         -- 470 ohm resistor  -- RED/GREEN/BLUE
  32.         -- 1  kohm resistor  -- RED/GREEN/BLUE
  33.   bit 0 -- 2.2kohm resistor  -- RED/GREEN/BLUE
  34.  
  35. ***************************************************************************/
  36. void commando_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  37. {
  38.     int i;
  39.  
  40.  
  41.     for (i = 0;i < Machine->drv->total_colors;i++)
  42.     {
  43.         int bit0,bit1,bit2,bit3;
  44.  
  45.  
  46.         bit0 = (color_prom[i] >> 0) & 0x01;
  47.         bit1 = (color_prom[i] >> 1) & 0x01;
  48.         bit2 = (color_prom[i] >> 2) & 0x01;
  49.         bit3 = (color_prom[i] >> 3) & 0x01;
  50.         palette[3*i] = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  51.         bit0 = (color_prom[i+Machine->drv->total_colors] >> 0) & 0x01;
  52.         bit1 = (color_prom[i+Machine->drv->total_colors] >> 1) & 0x01;
  53.         bit2 = (color_prom[i+Machine->drv->total_colors] >> 2) & 0x01;
  54.         bit3 = (color_prom[i+Machine->drv->total_colors] >> 3) & 0x01;
  55.         palette[3*i + 1] = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  56.         bit0 = (color_prom[i+2*Machine->drv->total_colors] >> 0) & 0x01;
  57.         bit1 = (color_prom[i+2*Machine->drv->total_colors] >> 1) & 0x01;
  58.         bit2 = (color_prom[i+2*Machine->drv->total_colors] >> 2) & 0x01;
  59.         bit3 = (color_prom[i+2*Machine->drv->total_colors] >> 3) & 0x01;
  60.         palette[3*i + 2] = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  61.     }
  62. }
  63.  
  64.  
  65.  
  66. /***************************************************************************
  67.  
  68.   Start the video hardware emulation.
  69.  
  70. ***************************************************************************/
  71. int commando_vh_start(void)
  72. {
  73.     if (generic_vh_start() != 0)
  74.         return 1;
  75.  
  76.     if ((dirtybuffer2 = malloc(commando_bgvideoram_size)) == 0)
  77.     {
  78.         generic_vh_stop();
  79.         return 1;
  80.     }
  81.     memset(dirtybuffer2,1,commando_bgvideoram_size);
  82.  
  83.     if (generic_vh_start() != 0)
  84.         return 1;
  85.  
  86.     /* the background area is twice as tall and twice as large as the screen */
  87.     if ((tmpbitmap2 = osd_create_bitmap(2*Machine->drv->screen_width,2*Machine->drv->screen_height)) == 0)
  88.     {
  89.         free(dirtybuffer2);
  90.         generic_vh_stop();
  91.         return 1;
  92.     }
  93.  
  94.     return 0;
  95. }
  96.  
  97.  
  98.  
  99. /***************************************************************************
  100.  
  101.   Stop the video hardware emulation.
  102.  
  103. ***************************************************************************/
  104. void commando_vh_stop(void)
  105. {
  106.     osd_free_bitmap(tmpbitmap2);
  107.     free(dirtybuffer2);
  108.     generic_vh_stop();
  109. }
  110.  
  111.  
  112.  
  113. WRITE_HANDLER( commando_bgvideoram_w )
  114. {
  115.     if (commando_bgvideoram[offset] != data)
  116.     {
  117.         dirtybuffer2[offset] = 1;
  118.  
  119.         commando_bgvideoram[offset] = data;
  120.     }
  121. }
  122.  
  123.  
  124.  
  125. WRITE_HANDLER( commando_bgcolorram_w )
  126. {
  127.     if (commando_bgcolorram[offset] != data)
  128.     {
  129.         dirtybuffer2[offset] = 1;
  130.  
  131.         commando_bgcolorram[offset] = data;
  132.     }
  133. }
  134.  
  135.  
  136.  
  137. WRITE_HANDLER( commando_spriteram_w )
  138. {
  139.     if (data != spriteram[offset] && offset % 4 == 2)
  140.         logerror("%04x: sprite %d X offset (old = %d new = %d) scanline %d\n",
  141.                 cpu_get_pc(),offset/4,spriteram[offset],data,255 - (cpu_getfcount() * 256 / cpu_getfperiod()));
  142.     if (data != spriteram[offset] && offset % 4 == 3)
  143.         logerror("%04x: sprite %d Y offset (old = %d new = %d) scanline %d\n",
  144.                 cpu_get_pc(),offset/4,spriteram[offset],data,255 - (cpu_getfcount() * 256 / cpu_getfperiod()));
  145.     if (data != spriteram[offset] && offset % 4 == 0)
  146.         logerror("%04x: sprite %d code (old = %d new = %d) scanline %d\n",
  147.                 cpu_get_pc(),offset/4,spriteram[offset],data,255 - (cpu_getfcount() * 256 / cpu_getfperiod()));
  148.  
  149.     spriteram[offset] = data;
  150. }
  151.  
  152.  
  153.  
  154. WRITE_HANDLER( commando_c804_w )
  155. {
  156.     /* bits 0 and 1 are for coin counters - we ignore them */
  157.  
  158.     /* bit 4 resets the sound CPU - we ignore it */
  159.  
  160.     /* bit 7 flips screen */
  161.     if (flipscreen != (~data & 0x80))
  162.     {
  163.         flipscreen = ~data & 0x80;
  164.         memset(dirtybuffer2,1,commando_bgvideoram_size);
  165.     }
  166. }
  167.  
  168.  
  169.  
  170. /***************************************************************************
  171.  
  172.   Draw the game screen in the given osd_bitmap.
  173.   Do NOT call osd_update_display() from this function, it will be called by
  174.   the main emulation engine.
  175.  
  176. ***************************************************************************/
  177. void commando_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  178. {
  179.     int offs;
  180.  
  181.  
  182.     for (offs = commando_bgvideoram_size - 1;offs >= 0;offs--)
  183.     {
  184.         if (dirtybuffer2[offs])
  185.         {
  186.             int sx,sy,flipx,flipy;
  187.  
  188.  
  189.             dirtybuffer2[offs] = 0;
  190.  
  191.             sx = offs / 32;
  192.             sy = offs % 32;
  193.             flipx = commando_bgcolorram[offs] & 0x10;
  194.             flipy = commando_bgcolorram[offs] & 0x20;
  195.             if (flipscreen)
  196.             {
  197.                 sx = 31 - sx;
  198.                 sy = 31 - sy;
  199.                 flipx = !flipx;
  200.                 flipy = !flipy;
  201.             }
  202.  
  203.             drawgfx(tmpbitmap2,Machine->gfx[1],
  204.                     commando_bgvideoram[offs] + 4*(commando_bgcolorram[offs] & 0xc0),
  205.                     commando_bgcolorram[offs] & 0x0f,
  206.                     flipx,flipy,
  207.                     16 * sx,16 * sy,
  208.                     0,TRANSPARENCY_NONE,0);
  209.         }
  210.     }
  211.  
  212.  
  213.     /* copy the background graphics */
  214.     {
  215.         int scrollx,scrolly;
  216.  
  217.  
  218.         scrollx = -(commando_scrolly[0] + 256 * commando_scrolly[1]);
  219.         scrolly = -(commando_scrollx[0] + 256 * commando_scrollx[1]);
  220.         if (flipscreen)
  221.         {
  222.             scrollx = 256 - scrollx;
  223.             scrolly = 256 - scrolly;
  224.         }
  225.  
  226.         copyscrollbitmap(bitmap,tmpbitmap2,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  227.     }
  228.  
  229.  
  230.     /* Draw the sprites. Note that it is important to draw them exactly in this */
  231.     /* order, to have the correct priorities. */
  232.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  233.     {
  234.         int sx,sy,flipx,flipy,bank;
  235.  
  236.  
  237.         /* bit 1 of [offs+1] is not used */
  238.  
  239.         sx = spriteram[offs + 3] - 0x100 * (spriteram[offs + 1] & 0x01);
  240.         sy = spriteram[offs + 2];
  241.         flipx = spriteram[offs + 1] & 0x04;
  242.         flipy = spriteram[offs + 1] & 0x08;
  243.         bank = (spriteram[offs + 1] & 0xc0) >> 6;
  244.  
  245.         if (flipscreen)
  246.         {
  247.             sx = 240 - sx;
  248.             sy = 240 - sy;
  249.             flipx = !flipx;
  250.             flipy = !flipy;
  251.         }
  252.  
  253.         if (bank < 3)
  254.             drawgfx(bitmap,Machine->gfx[2],
  255.                     spriteram[offs] + 256 * bank,
  256.                     (spriteram[offs + 1] & 0x30) >> 4,
  257.                     flipx,flipy,
  258.                     sx,sy,
  259.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,15);
  260.     }
  261.  
  262.  
  263.     /* draw the frontmost playfield. They are characters, but draw them as sprites */
  264.     for (offs = videoram_size - 1;offs >= 0;offs--)
  265.     {
  266.         int sx,sy,flipx,flipy;
  267.  
  268.  
  269.         sx = offs % 32;
  270.         sy = offs / 32;
  271.         flipx = colorram[offs] & 0x10;
  272.         flipy = colorram[offs] & 0x20;
  273.  
  274.         if (flipscreen)
  275.         {
  276.             sx = 31 - sx;
  277.             sy = 31 - sy;
  278.             flipx = !flipx;
  279.             flipy = !flipy;
  280.         }
  281.  
  282.         drawgfx(bitmap,Machine->gfx[0],
  283.                 videoram[offs] + 4 * (colorram[offs] & 0xc0),
  284.                 colorram[offs] & 0x0f,
  285.                 flipx,flipy,
  286.                 8*sx,8*sy,
  287.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,3);
  288.     }
  289. }
  290.